package com.yuexun.dhdoctor.module.personalPlan.presenter.impl;


import com.yuexun.dhdoctor.module.personalPlan.bean.CreatePlanBean;
import com.yuexun.dhdoctor.module.personalPlan.bean.UpdatePlanBean;
import com.yuexun.dhdoctor.module.personalPlan.model.IPlanEdtModel;
import com.yuexun.dhdoctor.module.personalPlan.presenter.IPlanEdtPresenter;
import com.yuexun.dhdoctor.module.personalPlan.ui.view.IPlanEdtView;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/9/7.
 */
public class PlanEdtPresenter implements IPlanEdtPresenter {
    private IPlanEdtView view;
    private IPlanEdtModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public PlanEdtPresenter(IPlanEdtModel model, IPlanEdtView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void createMyTask(Map<String, String> praise) {
        model.createMyTask(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<CreatePlanBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onNext(CreatePlanBean createPlanBean) {
                        view.createTask(createPlanBean);
                    }
                });
    }

    @Override
    public void updateMyTask(Map<String, String> praise) {
        model.updateMyTask(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UpdatePlanBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onNext(UpdatePlanBean updatePlanBean) {
                      view.updateTask(updatePlanBean);
                    }
                });
    }
}
